#include <stdio.h>
#include <stdlib.h>
//#include <windows.h>

typedef struct member
{
    int id;
    struct member *next;
};

int main()
{
    int m, n;
    int i;
    struct member *master;
    struct member *nextstu;
    struct member *laststu;
    struct member *oldstu;
    master = (struct member *)malloc(sizeof(struct member));
    master->next = master;
    master->id = 1;
    laststu = master;
    //printf("Please enter m & n :\n");
    scanf("%d %d", &m, &n);
    for (i = 2; i <= m; i++)
    {
        nextstu = (struct member *)malloc(sizeof(struct member));
        nextstu->id = i;
        laststu->next = nextstu;
        nextstu->next = master;
        if (i!=m)
        {
            laststu = laststu->next;
        }
    }
    oldstu = laststu;
    while (m != 0)
    {
        if(m != 1)
        {
            for (i = 0; i < n; i++)
            {
                laststu = laststu->next;
                master = master->next;
                if(i!=n-1)
                {
                    oldstu = oldstu->next;
                }
            }
            printf("%4d", laststu->next->id);
            free(laststu->next);
            laststu->next = master;
            laststu = oldstu;
        }
        else
        {
            printf("%4d", master->id);
            free(master);
        }
        m -= 1;
    }
    //system("pause");
    return 0;
}